package dk.itu.iwjx.helper;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
	
	public static String dbURL;
	public static String dbUserName;
	public static String dbPassword;		
	public static Connection conn;
	    /*
	     * Open database connection
	     */
	public static Connection getConn()
	    {
		    try {
		      Class.forName("com.mysql.jdbc.Driver");
		      conn = DriverManager.getConnection(dbURL, dbUserName,
		    		  dbPassword);
		      }
		    catch (SQLException e) {
		      System.out.println("Could not connect to DB");
		      e.printStackTrace();
		      } catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
		    	  System.out.println("driver class is not found");
				e.printStackTrace();
			}
		    return conn;
	    }
	    
	    /*
	     * Close open database connection
	     */
	    public static void close() 
	    {
		    if (conn != null) 
		    {
		    	try 
		    	{ 
		    		conn.close(); 
		    		conn = null;
		    	}
		      catch (SQLException e) {
		      	System.out.println("unable to close DB connection");
		      	e.printStackTrace(); }
		    }
	}
}
